import { Component, OnInit } from '@angular/core';
import { STMenu } from './classes/stmenu';
import { NavigationEnd, Router } from '@angular/router';
import { filter, Observable } from 'rxjs';
@Component({
  selector: 'app-admin',
  templateUrl: './admin.component.html',
  styleUrls: ['./admin.component.less'],
})
export class AdminComponent implements OnInit {
  menuList: STMenu[] = [
    {
      title: '系统首页',
      icon: 'home',
      link: 'admin/home',
    },
    {
      title: '订单管理',
      icon: 'profile',
      link: 'admin/order',
    },
    {
      title: '客户管理',
      icon: 'user',
      link: 'admin/user',
    },
  ];
  currentLink: string = 'admin/order';
  constructor(private router: Router) {
    (this.router.events.pipe(filter(event => event instanceof NavigationEnd)) as Observable<NavigationEnd>).subscribe(router => {     
      console.log(router)
      let url: string = router.urlAfterRedirects
      this.currentLink = url.slice(1, url.length)
    })
  }

  ngOnInit(): void { }
  handleList(e: STMenu) {
    this.router.navigateByUrl(e.link);
  }
}
